package cn.itsource.pet.controller;


import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.SearchMasterMessage;
import cn.itsource.pet.query.SearchMasterMessageQuery;
import cn.itsource.pet.service.ISearchMasterMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags={"店铺接口"})
@RestController //@Controller(交给spring管理) + @ResponseBody(方法返回json格式)
@RequestMapping("/searchMasterMessage")
public class SearchMasterMessageController {

    /**
     * 注入service层
     */
    @Autowired
    private ISearchMasterMessageService searchMasterMessageService;

    /**
     * 审核接口
     */

    //POST
    //	http://localhost/searchMasterMessage/shenghe/
    @PostMapping("/shenghe")
    public AjaxResult shenghe(@RequestBody SearchMasterMessage masterMessage){


        return searchMasterMessageService.shenghe(masterMessage);

    }
    /**
     * 发布宠物寻主的接口
     */

    //POST http://localhost/searchmaster/publish
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody SearchMasterMessage masterMessage){


        return searchMasterMessageService.publish(masterMessage);

    }


    /**
     * 查询所有的方法
     */
    @GetMapping
    private AjaxResult findAll(){
        //1.查询所有
        List<SearchMasterMessage> list = searchMasterMessageService.findAll();
        //2.封装对象返回
        return AjaxResult.createSuccess(list);
    }

    /**
     * 查询所有的方法
     */
    @PostMapping("/findPage")
    private PageList<SearchMasterMessage> findPage(@RequestBody SearchMasterMessageQuery searchMasterMessageQuery){

        //调用业务层 alt+enter
        //ctrl + t:快速往后找代码
        return searchMasterMessageService.findPage(searchMasterMessageQuery);
    }

    /**
     * 查询所有的方法
     */
    @GetMapping("/findOne/{id}")
    private AjaxResult findOne(@PathVariable("id") Long id){

        return AjaxResult.createSuccess(searchMasterMessageService.findOne(id));
    }

    /**
     * 新增或者修改  没有id就是新增  没有id就是修改
     * @param searchMasterMessage 店铺对象
     * eclipse风格:alt+shift+z 快速生成try
     * ctrl+shift+enter: 快速生成;
     */
    @PostMapping
    @ApiOperation(value="新增/修改店铺", notes="王天霸")
    public AjaxResult saveOrUpdate(@ApiParam(value = "新增/修改店铺参数", required = true) @RequestBody SearchMasterMessage searchMasterMessage){
        //调用service层
        try {
            searchMasterMessageService.saveOrUpdate(searchMasterMessage);
            return AjaxResult.createSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.createError("系统异常,请联系管理员");
        }
    }

    /**
     * 删除方法
     * @param id 主键id
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        //调用删除方法
        try {
            searchMasterMessageService.delete(id);
            return AjaxResult.createSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.createError("系统异常,请联系管理员");
        }
    }


}
